package com.example.util;


import java.util.HashMap;
import java.util.Map;

/**
  * @Author Fan bin bing
  * @Description  响应工具
  * @Date 2021/5/14 16:55
  **/
public class ResponseUtil {
    public static Object ok() {
        Map<String, Object> obj = new HashMap<>();
        obj.put("code", 0);
        obj.put("msg", "成功");
        return obj;
    }

    public static Object ok(Object data) {
        Map<String, Object> obj = new HashMap<>();
        obj.put("code", 0);
        obj.put("msg", "成功");
        obj.put("data", data);
        return obj;
    }

    public static Object okMsg(String msg) {
        Map<String, Object> obj = new HashMap<>();
        obj.put("code", 0);
        obj.put("msg", msg);
        return obj;
    }

//    public static Object okPage(Page page) {
//        Map<String, Object> data = new HashMap<>();
//        data.put("pages", page.getPages());
//        data.put("total", page.getTotal());
//        data.put("pageNum", page.getCurrent());
//        data.put("pageSize", page.getSize());
//        data.put("list", page.getRecords());
//        return ok(data);
//    }

    public static Object fail() {
        Map<String, Object> obj = new HashMap<>();
        obj.put("code", -1);
        obj.put("msg", "错误");
        return obj;
    }

    public static Object fail(int code, String msg) {
        Map<String, Object> obj = new HashMap<>();
        obj.put("code", code);
        obj.put("msg", msg);
        return obj;
    }

    public static Object fail(int code, String msg, String data) {
        Map<String, Object> obj = new HashMap<>(3);
        obj.put("code", code);
        obj.put("msg", msg);
        obj.put("data", data);
        return obj;
    }

    public static Object fail(String msg) {
        Map<String, Object> obj = new HashMap<>(2);
        obj.put("code", 409);
        obj.put("msg", msg);
        return obj;
    }

    public static Object badArgument() {
        return fail(401, "参数不对");
    }

    public static Object badArgumentValue() {
        return fail(402, "参数值不对");
    }

    public static Object unlogin() {
        return fail(501, "请登录");
    }

    public static Object serious() {
        return fail(502, "系统内部错误");
    }

    public static Object unsupport() {
        return fail(503, "业务不支持");
    }

    public static Object updatedDateExpired() {
        return fail(504, "更新数据已经失效");
    }

    public static Object updatedDataFailed() {
        return fail(505, "更新数据失败");
    }

    public static Object unauthz() {
        return fail(506, "无操作权限");
    }
}
